import cgi
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from entities import *
from Entities import *

def Add(countryName):
    country = db.GqlQuery("SELECT * FROM Country WHERE CountryName = :1",countryName)
    if country.count() == 0:
        country = Country(CountryName = countryName)
        country.put()
        return "Complete"
    else:
        return "Duplicate"

def Delete(countryName):
    country = db.GqlQuery("SELECT * FROM Country WHERE CountryName = :1",countryName)
    if country.count() == 0:
        return "No ..."
    else:
        Country.delete(country)
        return "Complete"
        
def Get():
    country_list = []
    countrys = db.GqlQuery("SELECT * FROM Country ORDER BY CountryName DESC")
    for country in countrys:
        country_dict = {}
        country_dict["CountryName"] = country.CountryName
        country_dict["CountryID"] = country.key().id()
        country_list.append(country_dict)
    tuple_country = tuple(country_list)
    return tuple_country
    